<template>
    <section>
        <el-row :gutter="40">
            <el-col :span="8">
                <sy-baselist
                        ref="roleList"
                        title="角色"
                        :hidePagination="true"
                        :hideHeader="true"
                        fixWhere="FID<>-1"
                        @current-change="onRoleChange"
                        @beforeDelete="beforeDelete"
                        editVue="./system/Role_Edit.vue"
                        listUrl="server/system/Role.ashx?cmd=GetRoleList"
                        deleteUrl="server/system/Role.ashx?cmd=DeleteRole"
                >
                    <el-table-column prop="FName" label="部门名称" width="150" sortable>
                    </el-table-column>

                </sy-baselist>
            </el-col>
            <el-col :span="14">
            <el-tabs active-name="first" >
                <el-tab-pane label="用户" name="first">
                    <sy-baselist
                        ref="roleUser"
                        :hideHeader="true"
                        :hideEdit="true"
                        @beforeAdd="beforeAddUser"
                        initWhere="1=2"
                        editVue="./system/User_Select.vue"
                        listUrl="server/system/Role.ashx?cmd=GetRoleUserList"
                        deleteUrl="server/system/Role.ashx?cmd=DeleteRoleUser"
                    >
                    <el-table-column prop="UserName" label="用户名" width="200" sortable>
                    </el-table-column>
                </sy-baselist>
                </el-tab-pane>
                <el-tab-pane label="部门" name="second"> <sy-baselist
                        ref="roleDept"
                        :hideHeader="true"
                        :hideEdit="true"
                        @beforeAdd="beforeAddDept"
                        initWhere="1=2"
                        editVue="./system/Dept_Select.vue"
                        listUrl="server/system/Role.ashx?cmd=GetRoleDeptList"
                        deleteUrl="server/system/Role.ashx?cmd=DeleteRoleDept"
                >
                    <el-table-column prop="DeptName" label="部门名称" width="200" sortable>
                    </el-table-column>
                </sy-baselist></el-tab-pane>
            </el-tabs>


            </el-col>
        </el-row>
    </section>
</template>

<script>
    import util from '../../common/util'
    export default {
        data(){
            return {
                FRoleID:0
            }
        },
        methods:{
            onRoleChange(row,oldRow){
                if(row) {
                    this.FRoleID = row.FID;
                    this.$refs.roleUser._search("FRoleID=" + row.FID);
                    this.$refs.roleDept._search("FRoleID=" + row.FID);
                }
            },
            beforeDelete(row,r){
                if(row.FID<0) {
                    return r.error = "系统内置角色，不能删除";
                }
            },
            ////////////////////////用户//////////////////////////////////
            beforeAddUser(row,r){
                if(this.FRoleID==0) {
                    return r.error = "请先选择角色";
                }
                row.FRoleID = this.FRoleID
            },
            beforeAddDept(row,r){
                if(this.FRoleID==0) {
                    return r.error = "请先选择角色";
                }
                row.FRoleID = this.FRoleID
            }
        }
    }
</script>